<?php
class ControllermoduleTreodencpanel extends Controller {
	private $error = array(); 

	public function index() {
		$this->language->load('module/treoden_cpanel');
		$this->document->setTitle($this->language->get('meta_title'));
		$this->load->model('setting/store');
		$this->load->model('module/treoden_cpanel');
		$this->model_module_treoden_cpanel->treodenInstall();
		$this->getList();
	}

  	public function update() {
    	$this->language->load('module/treoden_cpanel');
    	$this->document->setTitle($this->language->get('meta_title'));
		$this->load->model('setting/store');
		$this->load->model('module/treoden_cpanel');
    	if(($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
			/*layout builder update*/
			$store_id = $this->request->get['store_id'];
			if(isset($this->request->post['layout_id'])){
				$this->load->model('design/layout');
				$layout_id = $this->request->post['layout_id'];
				$layout = $this->model_design_layout->getLayout($this->request->post['layout_id']);
				$data['layout_name'] = $layout['name'];
				$data['layout_column'] = $this->request->post['columns'];
				if(isset($this->request->post['top_fluid'])){
					$content_top = array();
					foreach($this->request->post['top_fluid'] as  $value){
						$value = htmlspecialchars_decode($value);
						$value = json_decode($value, true);
						$content_top[] = $value;
					}
					$content_top = json_encode($content_top);
					$data['content_top'] = $content_top;
				}
				else
					$data['content_top'] = '';
					
				if(isset($this->request->post['bottom_fluid'])){
					$content_bottom = array();
					foreach($this->request->post['bottom_fluid'] as  $value){
						$value = htmlspecialchars_decode($value);
						$value = json_decode($value, true);
						$content_bottom[] = $value;
					}
					$content_bottom = json_encode($content_bottom);
					$data['content_bottom'] = $content_bottom;
				}
				else
					$data['content_bottom'] = '';
				
				$this->model_module_treoden_cpanel->treodenUpdateLayout($store_id, $layout_id, $data);		

				$this->model_module_treoden_cpanel->treodenSaveLayoutOption($store_id, "sort_order_top_".$layout_id, $this->request->post['sort_order_top']);		
				$this->model_module_treoden_cpanel->treodenSaveLayoutOption($store_id, "sort_order_bottom_".$layout_id, $this->request->post['sort_order_bottom']);		
			}
			/*options update*/
			$this->model_module_treoden_cpanel->treodenSaveSettingOption($store_id, $this->request->post);
			
			$this->session->data['success'] = $this->language->get('text_success');
			
			$this->redirect($this->url->link('module/treoden_cpanel', 'token=' . $this->session->data['token'] . '&store_id=' . $this->request->get['store_id'], 'SSL'));
		}

    	$this->getForm();
  	}
	protected function getList() {
		$this->load->model('setting/store');
		$url = '';
			
		if (isset($this->request->get['page'])) {
			$url .= '&page=' . $this->request->get['page'];
		}

  		$this->data['breadcrumbs'] = array();

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => false
   		);

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('module/treoden_cpanel', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);
		$this->data['stores'] = array();
		
		$action = array();
					
		$action[] = array(
			'text' => $this->language->get('text_edit'),
			'href' => $this->url->link('module/treoden_cpanel/update', 'token=' . $this->session->data['token'].'&store_id=0', 'SSL')
		);
					
		$this->data['stores'][] = array(
			'store_id' => 0,
			'name'     => $this->config->get('config_name') . $this->language->get('text_default'),
			'url'      => HTTP_CATALOG,
			'action'   => $action
		);
					
		$store_total = $this->model_setting_store->getTotalStores();
	
		$results = $this->model_setting_store->getStores();
 
    	foreach ($results as $result) {
			$action = array();
						
			$action[] = array(
				'text' => $this->language->get('text_edit'),
				'href' => $this->url->link('module/treoden_cpanel/update', 'token=' . $this->session->data['token'] . '&store_id=' . $result['store_id'], 'SSL')
			);
						
			$this->data['stores'][] = array(
				'store_id' => $result['store_id'],
				'name'     => $result['name'],
				'url'      => $result['url'],
				'action'   => $action
			);
		}	
	
		$this->data['heading_title'] = $this->language->get('meta_title');

		$this->data['text_no_results'] = $this->language->get('text_no_results');

		$this->data['column_name'] = $this->language->get('column_name');
		$this->data['column_url'] = $this->language->get('column_url');
		$this->data['column_action'] = $this->language->get('column_action');		
		
 		if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		} else {
			$this->data['error_warning'] = '';
		}
		
		if (isset($this->session->data['success'])) {
			$this->data['success'] = $this->session->data['success'];
		
			unset($this->session->data['success']);
		} else {
			$this->data['success'] = '';
		}

		$this->template = 'module/treoden_store_list.tpl';
		$this->children = array(
			'common/header',
			'common/footer'
		);
				
		$this->response->setOutput($this->render());
	}
	 
	public function getForm() { 
		$this->data['heading_title'] = $this->language->get('meta_title');
		$this->data['select_layout'] = $this->language->get('select_layout');		
		$this->data['button_save'] = $this->language->get('button_save');
		$this->data['button_cancel'] = $this->language->get('button_cancel');
		/*tabs*/
		$this->data['tab_general'] = $this->language->get('tab_general');
		$this->data['tab_body'] = $this->language->get('tab_body');
		$this->data['tab_header'] = $this->language->get('tab_header');
		$this->data['tab_menu'] = $this->language->get('tab_menu');
		$this->data['tab_footer'] = $this->language->get('tab_footer');
		$this->data['tab_product_item'] = $this->language->get('tab_product_item');
		$this->data['tab_products_block'] = $this->language->get('tab_products_block');
		$this->data['tab_category_page'] = $this->language->get('tab_category_page');
		$this->data['tab_product_page'] = $this->language->get('tab_product_page');
		$this->data['layout_config'] = $this->language->get('layout_config');
		$this->data['special_offers'] = $this->language->get('special_offers');
		$this->data['entry_product'] = $this->language->get('entry_product');
		$this->document->addStyle('view/stylesheet/treodenthemes/style.css');
		$this->document->addStyle('view/stylesheet/treodenthemes/bootstrap.css');
		$this->document->addStyle('view/stylesheet/treodenthemes/colorpicker.css');
		$this->document->addScript('view/javascript/treodenthemes/colorpicker.js');
		$this->document->addScript('view/javascript/ckeditor/ckeditor.js');
		/*form validate*/
		$this->data['feild_error_message'] = $this->language->get('feild_error_message');
		$this->data['form_error_message'] = $this->language->get('form_error_message');
		
 		if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		} else {
			$this->data['error_warning'] = '';
		}
		
  		$this->data['breadcrumbs'] = array();

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => false
   		);

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('module/treoden_cpanel', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);
		
		if (isset($this->session->data['success'])) {
			$this->data['success'] = $this->session->data['success'];
		
			unset($this->session->data['success']);
		} else {
			$this->data['success'] = '';
		}
		$this->load->model('localisation/language');
		$this->data['languages'] = $this->model_localisation_language->getLanguages();
		/*Load Layout*/
		$this->load->model('design/layout');
		
		$this->data['layouts'] = $this->model_design_layout->getLayouts();
		$this->data['action'] = $this->url->link('module/treoden_cpanel/update', 'token=' . $this->session->data['token'] . '&store_id=' . $this->request->get['store_id'], 'SSL');
		$this->data['import_action'] = $this->url->link('module/treoden_cpanel/import', 'token=' . $this->session->data['token'] . '&store_id=' . $this->request->get['store_id'], 'SSL');

				
		$this->data['cancel'] = $this->url->link('module/treoden_cpanel', 'token=' . $this->session->data['token'], 'SSL');
	
		if (isset($this->request->get['store_id'])) {
			$this->load->model('module/treoden_cpanel');
			
      		$config_info = $this->model_module_treoden_cpanel->getSetting( $this->request->get['store_id']);
    	}
		
		$this->data['token'] = $this->session->data['token'];
		
		if (isset($config_info['wide_boxed'])) {
			$this->data['wide_boxed'] = $config_info['wide_boxed'];
		} else {
			$this->data['wide_boxed'] = 'wide';
		}
		if (isset($config_info['full_slide_show_mode'])) {
			$this->data['full_slide_show_mode'] = $config_info['full_slide_show_mode'];
		} else {
			$this->data['full_slide_show_mode'] = 'no';
		}
		if (isset($config_info['image_full_resource'])) {
			$this->data['image_full_resource'] = $config_info['image_full_resource'];
		} else {
			$this->data['image_full_resource'] = 0;
		}
		if (isset($config_info['slide_interval'])) {
			$this->data['slide_interval'] = $config_info['slide_interval'];
		} else {
			$this->data['slide_interval'] = 3000;
		}
		if (isset($config_info['slide_transition'])) {
			$this->data['slide_transition'] = $config_info['slide_transition'];
		} else {
			$this->data['slide_transition'] = 1;
		}
		if (isset($config_info['transition_speed'])) {
			$this->data['transition_speed'] = $config_info['transition_speed'];
		} else {
			$this->data['transition_speed'] = 700;
		}
		if (isset($config_info['main_width'])) {
			$this->data['main_width'] = $config_info['main_width'];
		} else {
			$this->data['main_width'] = 1180;
		}
		if (isset($config_info['font_family'])) {
			$this->data['font_family'] = $config_info['font_family'];
		} else {
			$this->data['font_family'] = "Muli";
		}
		$this->data['google_font_body']=$this->model_module_treoden_cpanel->treodenGoogleFont($this->data['font_family']);
		if (isset($config_info['font_size'])) {
			$this->data['font_size'] = $config_info['font_size'];
		} else {
			$this->data['font_size'] = 14;
		}
		if (isset($config_info['font_color'])) {
			$this->data['font_color'] = $config_info['font_color'];
		} else {
			$this->data['font_color'] = '818482';
		}
		if (isset($config_info['primary_color'])) {
			$this->data['primary_color'] = $config_info['primary_color'];
		} else {
			$this->data['primary_color'] = '004e32';
		}
		if (isset($config_info['secondary_color'])) {
			$this->data['secondary_color'] = $config_info['secondary_color'];
		} else {
			$this->data['secondary_color'] = '000000';
		}
		if (isset($config_info['border_color'])) {
			$this->data['border_color'] = $config_info['border_color'];
		} else {
			$this->data['border_color'] = 'cccccc';
		}
		if (isset($config_info['background_image'])) {
			$this->data['background_image'] = $config_info['background_image'];			
		} else {
			$this->data['background_image'] = '';
		}
		$this->load->model('tool/image');
		$this->data['no_image'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
		if (isset($config_info['background_image']) && file_exists(DIR_IMAGE . $config_info['background_image']) && is_file(DIR_IMAGE . $config_info['background_image'])) {
			$this->data['background_image_url'] = $this->model_tool_image->resize($config_info['background_image'], 100, 100);		
		} else {
			$this->data['background_image_url'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
		}
		if (isset($config_info['background_position'])) {
			$this->data['background_position'] = $config_info['background_position'];
		} else {
			$this->data['background_position'] = 'top-left';
		}
		if (isset($config_info['background_repeat'])) {
			$this->data['background_repeat'] = $config_info['background_repeat'];
		} else {
			$this->data['background_repeat'] = 'none';
		}
		if (isset($config_info['background_color'])) {
			$this->data['background_color'] = $config_info['background_color'];
		} else {
			$this->data['background_color'] = 'ffffff';
		}
		if (isset($config_info['background_container_color'])) {
			$this->data['background_container_color'] = $config_info['background_container_color'];
		} else {
			$this->data['background_container_color'] = '';
		}
		/*if (isset($config_info['slider_animation'])) {
			$this->data['slider_animation'] = $config_info['slider_animation'];
		} else {
			$this->data['slider_animation'] = 'random';
		}
		if (isset($config_info['slider_delay_time'])) {
			$this->data['slider_delay_time'] = $config_info['slider_delay_time'];
		} else {
			$this->data['slider_delay_time'] = 3;
		}*/
		if (isset($config_info['font_of_bar_title'])) {
			$this->data['font_of_bar_title'] = $config_info['font_of_bar_title'];
		} else {
			$this->data['font_of_bar_title'] = "Cinzel";
		}
		$this->data['google_font_of_bar_title']=$this->model_module_treoden_cpanel->treodenGoogleFont($this->data['font_of_bar_title']);
		if (isset($config_info['color_of_bar_title'])) {
			$this->data['color_of_bar_title'] = $config_info['color_of_bar_title'];
		} else {
			$this->data['color_of_bar_title'] = '999';
		}
		if (isset($config_info['font_size_of_bar_title'])) {
			$this->data['font_size_of_bar_title'] = $config_info['font_size_of_bar_title'];
		} else {
			$this->data['font_size_of_bar_title'] = 26;
		}
		if (isset($config_info['font_style_of_bar_title'])) {
			$this->data['font_style_of_bar_title'] = $config_info['font_style_of_bar_title'];
		} else {
			$this->data['font_style_of_bar_title'] = 'regular';
		}
		/*if (isset($config_info['color_of_bar_border'])) {
			$this->data['color_of_bar_border'] = $config_info['color_of_bar_border'];
		} else {
			$this->data['color_of_bar_border'] = 'FF9D4C';
		}
		if (isset($config_info['think_of_bar_border'])) {
			$this->data['think_of_bar_border'] = $config_info['think_of_bar_border'];
		} else {
			$this->data['think_of_bar_border'] = 3;
		}*/
		if (isset($config_info['color_of_bar_backround_top'])) {
			$this->data['color_of_bar_backround_top'] = $config_info['color_of_bar_backround_top'];
		} else {
			$this->data['color_of_bar_backround_top'] = '';
		}
		if (isset($config_info['color_of_bar_backround_bottom'])) {
			$this->data['color_of_bar_backround_bottom'] = $config_info['color_of_bar_backround_bottom'];
		} else {
			$this->data['color_of_bar_backround_bottom'] = '';
		}
		/*if (isset($config_info['border_radius_of_bar_background'])) {
			$this->data['border_radius_of_bar_background'] = $config_info['border_radius_of_bar_background'];
		} else {
			$this->data['border_radius_of_bar_background'] = 0;
		}*/
		if (isset($config_info['height_of_bar'])) {
			$this->data['height_of_bar'] = $config_info['height_of_bar'];
		} else {
			$this->data['height_of_bar'] = 30;
		}
		/*button*/
		
		if (isset($config_info['font_of_button_text'])) {
			$this->data['font_of_button_text'] = $config_info['font_of_button_text'];
		} else {
			$this->data['font_of_button_text'] = "Muli";
		}
		$this->data['google_font_of_button_text']=$this->model_module_treoden_cpanel->treodenGoogleFont($this->data['font_of_button_text']);
		if (isset($config_info['font_style_of_button_text'])) {
			$this->data['font_style_of_button_text'] = $config_info['font_style_of_button_text'];
		} else {
			$this->data['font_style_of_button_text'] = 'regular';
		}
		if (isset($config_info['color_of_button_text'])) {
			$this->data['color_of_button_text'] = $config_info['color_of_button_text'];
		} else {
			$this->data['color_of_button_text'] = 'ffffff';
		}
		if (isset($config_info['font_size_of_button_text'])) {
			$this->data['font_size_of_button_text'] = $config_info['font_size_of_button_text'];
		} else {
			$this->data['font_size_of_button_text'] = 14;
		}
		if (isset($config_info['color_of_button_backround_top'])) {
			$this->data['color_of_button_backround_top'] = $config_info['color_of_button_backround_top'];
		} else {
			$this->data['color_of_button_backround_top'] = '000000';
		}
		if (isset($config_info['color_of_button_backround_bottom'])) {
			$this->data['color_of_button_backround_bottom'] = $config_info['color_of_button_backround_bottom'];
		} else {
			$this->data['color_of_button_backround_bottom'] = '000000';
		}
		/*
		if (isset($config_info['border_color_of_button'])) {
			$this->data['border_color_of_button'] = $config_info['border_color_of_button'];
		} else {
			$this->data['border_color_of_button'] = '313131';
		}
		*/
		if (isset($config_info['color_of_button_text_hover'])) {
			$this->data['color_of_button_text_hover'] = $config_info['color_of_button_text_hover'];
		} else {
			$this->data['color_of_button_text_hover'] = 'ffffff';
		}
		/*
		if (isset($config_info['border_color_of_button_hover'])) {
			$this->data['border_color_of_button_hover'] = $config_info['border_color_of_button_hover'];
		} else {
			$this->data['border_color_of_button_hover'] = '313131';
		}*/
		if (isset($config_info['color_of_button_backround_top_hover'])) {
			$this->data['color_of_button_backround_top_hover'] = $config_info['color_of_button_backround_top_hover'];
		} else {
			$this->data['color_of_button_backround_top_hover'] = '';
		}
		if (isset($config_info['color_of_button_backround_bottom_hover'])) {
			$this->data['color_of_button_backround_bottom_hover'] = $config_info['color_of_button_backround_bottom_hover'];
		} else {
			$this->data['color_of_button_backround_bottom_hover'] = '';
		}
		/*
		if (isset($config_info['width_control_carousel_button'])) {
			$this->data['width_control_carousel_button'] = $config_info['width_control_carousel_button'];
		} else {
			$this->data['width_control_carousel_button'] = 20;
		}
		if (isset($config_info['height_control_carousel_button'])) {
			$this->data['height_control_carousel_button'] = $config_info['height_control_carousel_button'];
		} else {
			$this->data['height_control_carousel_button'] = 18;
		}
		if (isset($config_info['background_button_control_carousel'])) {
			$this->data['background_button_control_carousel'] = $config_info['background_button_control_carousel'];
		} else {
			$this->data['background_button_control_carousel'] = "c9ab8b";
		}
		if (isset($config_info['radius_control_carousel_button'])) {
			$this->data['radius_control_carousel_button'] = $config_info['radius_control_carousel_button'];
		} else {
			$this->data['radius_control_carousel_button'] = 0;
		}
		*/
		if (isset($config_info['link_color'])) {
			$this->data['link_color'] = $config_info['link_color'];
		} else {
			$this->data['link_color'] = "818482";
		}
		if (isset($config_info['link_color_hover'])) {
			$this->data['link_color_hover'] = $config_info['link_color_hover'];
		} else {
			$this->data['link_color_hover'] = "";
		}
		if (isset($config_info['html_heading_color'])) {
			$this->data['html_heading_color'] = $config_info['html_heading_color'];
		} else {
			$this->data['html_heading_color'] = "121212";
		}
		if (isset($config_info['font_of_html_heading'])) {
			$this->data['font_of_html_heading'] = $config_info['font_of_html_heading'];
		} else {
			$this->data['font_of_html_heading'] = "Cinzel";
		}
		$this->data['font_of_html_heading']=$this->model_module_treoden_cpanel->treodenGoogleFont($this->data['font_of_html_heading']);
		if (isset($config_info['custom_css'])) {
			$this->data['custom_css'] = $config_info['custom_css'];
		} else {
			$this->data['custom_css'] = "";
		}
		/*header*/
		if (isset($config_info['header_display_style'])) {
			$this->data['header_display_style'] = $config_info['header_display_style'];
		} else {
			$this->data['header_display_style'] = 'center-logo';
		}
		if (isset($config_info['display_language'])) {
			$this->data['display_language'] = $config_info['display_language'];
		} else {
			$this->data['display_language'] = 'yes';
		}
		if (isset($config_info['display_currency'])) {
			$this->data['display_currency'] = $config_info['display_currency'];
		} else {
			$this->data['display_currency'] = 'yes';
		}
		if (isset($config_info['display_links'])) {
			$this->data['display_links'] = $config_info['display_links'];
		} else {
			$this->data['display_links'] = 'yes';
		}
		if (isset($config_info['display_social_icons'])) {
			$this->data['display_social_icons'] = $config_info['display_social_icons'];
		} else {
			$this->data['display_social_icons'] = 'yes';
		}
		if (isset($config_info['social_icons_html'])) {
			$this->data['social_icons_html'] = $config_info['social_icons_html'];
		} else {
			$this->data['social_icons_html'] = '<a class="icon-facebook" href="#"></a><a class="icon-twitter" href="#"></a><a class="icon-feed2" href="#"></a><a class="icon-google-plus" href="#"></a><a class="icon-vimeo" href="#"></a>';
		}
		/*if (isset($config_info['background_image_header'])) {
			$this->data['background_image_header'] = $config_info['background_image_header'];			
		} else {
			$this->data['background_image_header'] = '';
		}
		if (isset($config_info['']) && file_exists(DIR_IMAGE . $config_info['background_image_header']) && is_file(DIR_IMAGE . $config_info['background_image_header'])) {
			$this->data['background_image_header_url'] = $this->model_tool_image->resize($config_info['background_image_header'], 100, 100);		
		} else {
			$this->data['background_image_header_url'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
		}
		if (isset($config_info['background_position_header'])) {
			$this->data['background_position_header'] = $config_info['background_position_header'];
		} else {
			$this->data['background_position_header'] = 'top-left';
		}
		if (isset($config_info['bacbackground_image_headerkground_repeat_header'])) {
			$this->data['background_repeat_header'] = $config_info['background_repeat_header'];
		} else {
			$this->data['background_repeat_header'] = 'repeat-x';
		}*/
		if (isset($config_info['background_top_header_bar_color_header'])) {
			$this->data['background_top_header_bar_color_header'] = $config_info['background_top_header_bar_color_header'];
		} else {
			$this->data['background_top_header_bar_color_header'] = '000000';
		}
		if (isset($config_info['background_color_header'])) {
			$this->data['background_color_header'] = $config_info['background_color_header'];
		} else {
			$this->data['background_color_header'] = '';
		}
		/*Menu*/
		if (isset($config_info['active_sticky_menu'])) {
			$this->data['active_sticky_menu'] = $config_info['active_sticky_menu'];
		} else {
			$this->data['active_sticky_menu'] = 'yes';
		}
		if (isset($config_info['menu_font_family'])) {
			$this->data['menu_font_family'] = $config_info['menu_font_family'];
		} else {
			$this->data['menu_font_family'] = '';
		}
		$this->data['google_menu_font']=$this->model_module_treoden_cpanel->treodenGoogleFont($this->data['menu_font_family']);
		if (isset($config_info['font_size_menu'])) {
			$this->data['font_size_menu'] = $config_info['font_size_menu'];
		} else {
			$this->data['font_size_menu'] = 16;
		}

		if (isset($config_info['color_of_menu_backround_top'])) {
			$this->data['color_of_menu_backround_top'] = $config_info['color_of_menu_backround_top'];
		} else {
			$this->data['color_of_menu_backround_top'] = "";
		}
		if (isset($config_info['color_of_menu_backround_bottom'])) {
			$this->data['color_of_menu_backround_bottom'] = $config_info['color_of_menu_backround_bottom'];
		} else {
			$this->data['color_of_menu_backround_bottom'] = "";
		}
		if (isset($config_info['color_of_menu_font'])) {
			$this->data['color_of_menu_font'] = $config_info['color_of_menu_font'];
		} else {
			$this->data['color_of_menu_font'] = "";
		}
		if (isset($config_info['color_of_menu_font_hover'])) {
			$this->data['color_of_menu_font_hover'] = $config_info['color_of_menu_font_hover'];
		} else {
			$this->data['color_of_menu_font_hover'] = "";
		}
		if (isset($config_info['color_of_menu_backround_top_hover'])) {
			$this->data['color_of_menu_backround_top_hover'] = $config_info['color_of_menu_backround_top_hover'];
		} else {
			$this->data['color_of_menu_backround_top_hover'] = "";
		}
		if (isset($config_info['color_of_menu_backround_bottom_hover'])) {
			$this->data['color_of_menu_backround_bottom_hover'] = $config_info['color_of_menu_backround_bottom_hover'];
		} else {
			$this->data['color_of_menu_backround_bottom_hover'] = "";
		}
		if (isset($config_info['color_of_submenu_background'])) {
			$this->data['color_of_submenu_background'] = $config_info['color_of_submenu_background'];
		} else {
			$this->data['color_of_submenu_background'] = "ffffff";
		}
		if (isset($config_info['color_of_menu_lines'])) {
			$this->data['color_of_menu_lines'] = $config_info['color_of_menu_lines'];
		} else {
			$this->data['color_of_menu_lines'] = "";
		}
		/*Footer*/
		$default_content = array();
		foreach($this->data['languages'] as $key=>$language){
			$default_content[$language['language_id']] = '
		<div class="pure-u-1-3">
		<div class="col-inner">
		<div class="our-blog">
		<h2>PEOPLE SAYING</h2>
		<div class="content"><a class="title">Suspendisse aliquet venena ugue rutO Aliquam ac nunc felis augue erat </a>
		<p class="time">Friday, 23 December 2013</p>
		<a class="read-more">........</a> <a class="title">Suspendisse aliquet venena ugue rutO Aliquam ac nunc felis augue erat </a>
		<p class="time">Friday, 23 December 2013</p>
		<a class="read-more">........</a> <a class="title">Suspendisse aliquet venena ugue rutO Aliquam ac nunc felis augue erat </a>
		<p class="time">Friday, 23 December 2013</p>
		<a class="read-more">........</a></div>
		</div>
		</div>
		</div>
		<div class="pure-u-1-3">
		<div class="col-inner">
		<div class="our-mission">
		<h2>OUR MISSION</h2>
		<div class="content"><a class="title">Aenean non mattis diam Sed ornare </a>
		<p>Suspendisse aliquet venenatis augue at rutrum Aliquam ac nunc felis. Ut in ultrices augue uliquam erat volutpat. Donec libero nunc, fermentum sed</p>
		<a class="title">Aenean non mattis diam Sed ornare </a>
		<p>Suspendisse aliquet venenatis augue at rutrum Aliquam ac nunc felis. Ut in ultrices augue uliquam erat volutpat. Donec libero nunc, fermentum sed</p>
		<a class="button"><span>READ MORE</span></a></div>
		</div>
		</div>
		</div>
		<div class="pure-u-1-3">
		<div class="col-inner">
		<div class="our-blog">
		<h2>OUTLET STORE</h2>
		<div class="content"><a><img alt="" src="http://treodenthemes.com/demo/timeout/watch/image/data/outlet-store.png" /></a>
		<p>Nulla posuere nunc eget diam consequat posuere in eu est duis eu elit sit amet metus vestibulum urna ornare dolor at metus gravida, ullamcorper</p>
		<a class="button"><span>FIND STORE</span></a></div>
		</div>
		</div>
		</div>';
		}
		if (isset($config_info['top_footer_content'])) {
			$this->data['top_footer_content'] = unserialize(base64_decode($config_info['top_footer_content']));
		} else {
			$this->data['top_footer_content'] = $default_content;
		}
		$default_content = array();
		foreach($this->data['languages'] as $key=>$language){
			$default_content[$language['language_id']] = '<div class="pure-hidden-phone" style="text-align:center;margin-bottom:35px"><img alt="" src="http://treodenthemes.com/demo/timeout/watch/image/data/chat-with-us-banner.jpg" /></div>
		<div class="pure-u-1-6">
		<div class="col-inner">
		<div class="block-title">cursus Phasellus</div>
		<ul class="block-content">
			<li><a href="#">Suspendisse aliquet</a></li>
			<li><a href="#">Venenatis augue rutrum</a></li>
			<li><a href="#">Aliquam ac nunc fe</a></li>
			<li><a href="#">Venenatis augue rutrum</a></li>
			<li><a href="#">Aliquam ac nunc fe</a></li>
			<li><a href="#">Suspendisse aliquet</a></li>
		</ul>
		</div>
		</div>
		<div class="pure-u-1-6">
		<div class="col-inner">
		<div class="block-title">ultricies non sem</div>
		<ul class="block-content">
			<li><a href="#">Suspendisse aliquet</a></li>
			<li><a href="#">Venenatis augue rutrum</a></li>
			<li><a href="#">Aliquam ac nunc fe</a></li>
			<li><a href="#">Venenatis augue rutrum</a></li>
			<li><a href="#">Aliquam ac nunc fe</a></li>
			<li><a href="#">Suspendisse aliquet</a></li>
		</ul>
		</div>
		</div>
		<div class="pure-u-1-6">
		<div class="col-inner">
		<div class="block-title">venenatis enim sed</div>
		<ul class="block-content">
			<li><a href="#">Suspendisse aliquet</a></li>
			<li><a href="#">Venenatis augue rutrum</a></li>
			<li><a href="#">Aliquam ac nunc fe</a></li>
			<li><a href="#">Venenatis augue rutrum</a></li>
			<li><a href="#">Aliquam ac nunc fe</a></li>
			<li><a href="#">Suspendisse aliquet</a></li>
		</ul>
		</div>
		</div>
		<div class="pure-u-1-6">
		<div class="col-inner">
		<div class="block-title">rutrum eleifendas</div>
		<ul class="block-content">
			<li><a href="#">Suspendisse aliquet</a></li>
			<li><a href="#">Venenatis augue rutrum</a></li>
			<li><a href="#">Aliquam ac nunc fe</a></li>
			<li><a href="#">Venenatis augue rutrum</a></li>
			<li><a href="#">Aliquam ac nunc fe</a></li>
			<li><a href="#">Suspendisse aliquet</a></li>
		</ul>
		</div>
		</div>
		<div class="pure-u-1-6">
		<div class="col-inner">
		<div class="block-title">Maecenas facilisis</div>
		<ul class="block-content">
			<li><a href="#">Suspendisse aliquet</a></li>
			<li><a href="#">Venenatis augue rutrum</a></li>
			<li><a href="#">Aliquam ac nunc fe</a></li>
			<li><a href="#">Venenatis augue rutrum</a></li>
			<li><a href="#">Aliquam ac nunc fe</a></li>
			<li><a href="#">Suspendisse aliquet</a></li>
		</ul>
		</div>
		</div>
		<div class="pure-u-1-6">
		<div class="col-inner">
		<div class="block-title">Phasellus blandit</div>
		<ul class="block-content">
			<li><a href="#">Suspendisse aliquet</a></li>
			<li><a href="#">Venenatis augue rutrum</a></li>
			<li><a href="#">Aliquam ac nunc fe</a></li>
			<li><a href="#">Venenatis augue rutrum</a></li>
			<li><a href="#">Aliquam ac nunc fe</a></li>
			<li><a href="#">Suspendisse aliquet</a></li>
		</ul>
		</div>
		</div>';
		}
		if (isset($config_info['footer_content'])) {
			$this->data['footer_content'] = unserialize(base64_decode($config_info['footer_content']));
		} else {
			$this->data['footer_content'] = $default_content;
		}
		/*
		if (isset($config_info['background_image_footer'])) {
			$this->data['background_image_footer'] = $config_info['background_image_footer'];			
		} else {
			$this->data['background_image_footer'] = '';
		}
		if (isset($config_info['background_image_footer']) && file_exists(DIR_IMAGE . $config_info['background_image_footer']) && is_file(DIR_IMAGE . $config_info['background_image_footer'])) {
			$this->data['background_image_footer_url'] = $this->model_tool_image->resize($config_info['background_image_footer'], 100, 100);		
		} else {
			$this->data['background_image_footer_url'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
		}
		if (isset($config_info['background_position_footer'])) {
			$this->data['background_position_footer'] = $config_info['background_position_footer'];
		} else {
			$this->data['background_position_footer'] = 'top-left';
		}
		if (isset($config_info['background_repeat_footer'])) {
			$this->data['background_repeat_footer'] = $config_info['background_repeat_footer'];
		} else {
			$this->data['background_repeat_footer'] = 'repeat-x';
		}*/
		if (isset($config_info['background_color_footer'])) {
			$this->data['background_color_footer'] = $config_info['background_color_footer'];
		} else {
			$this->data['background_color_footer'] = '';
		}
		
		if (isset($config_info['copyright_text'])) {
			$this->data['copyright_text'] = $config_info['copyright_text'];
		} else {
			$this->data['copyright_text'] = "© 2014 Timeout Store designed by <a href='http://www.treodenthemes.com'>Treodenthemes</a>. All rights reserved.";
		}
		if (isset($config_info['link_color_footer'])) {
			$this->data['link_color_footer'] = $config_info['link_color_footer'];
		} else {
			$this->data['link_color_footer'] = "818482";
		}
		if (isset($config_info['link_color_footer_hover'])) {
			$this->data['link_color_footer_hover'] = $config_info['link_color_footer_hover'];
		} else {
			$this->data['link_color_footer_hover'] = "";
		}
		if (isset($config_info['html_heading_footer_color'])) {
			$this->data['html_heading_footer_color'] = $config_info['html_heading_footer_color'];
		} else {
			$this->data['html_heading_footer_color'] = "212422";
		}
		if (isset($config_info['font_of_html_heading_footer'])) {
			$this->data['font_of_html_heading_footer'] = $config_info['font_of_html_heading_footer'];
		} else {
			$this->data['font_of_html_heading_footer'] = "Cinzel";
		}
		$this->data['font_of_html_heading_footer']=$this->model_module_treoden_cpanel->treodenGoogleFont($this->data['font_of_html_heading_footer']);
		if (isset($config_info['payment_icons_src'])) {
			$this->data['payment_icons_src'] = unserialize(base64_decode($config_info['payment_icons_src']));
		} else {
			$this->data['payment_icons_src'] = array('data/timeout-payment-visa.png','data/timeout-payment-mastercard.png','data/timeout-payment-american-express.png','data/timeout-payment-paypal.png');
		}
		if (isset($config_info['payment_icons_link'])) {
			$this->data['payment_icons_link'] = unserialize(base64_decode($config_info['payment_icons_link']));
		} else {
			$this->data['payment_icons_link'] = array('', '', '', '');
		}
		if (isset($config_info['payment_icons_name'])) {
			$this->data['payment_icons_name'] = unserialize(base64_decode($config_info['payment_icons_name']));
		} else {
			$this->data['payment_icons_name'] = array('Visa', 'MasterCard', 'American Express', 'Paypal');
		}
		/*products block*/
		if (isset($config_info['featured_product_display_style'])) {
			$this->data['featured_product_display_style'] = $config_info['featured_product_display_style'];
		} else {
			$this->data['featured_product_display_style'] = 'list-carousel';
		}
		if (isset($config_info['num_of_products_featured'])) {
			$this->data['num_of_products_featured'] = $config_info['num_of_products_featured'];
		} else {
			$this->data['num_of_products_featured'] = 4;
		}
		if (isset($config_info['lastest_product_display_style'])) {
			$this->data['lastest_product_display_style'] = $config_info['lastest_product_display_style'];
		} else {
			$this->data['lastest_product_display_style'] = 'grid-carousel';
		}
		if (isset($config_info['num_of_products_lastest'])) {
			$this->data['num_of_products_lastest'] = $config_info['num_of_products_lastest'];
		} else {
			$this->data['num_of_products_lastest'] = 4;
		}
		if (isset($config_info['special_product_display_style'])) {
			$this->data['special_product_display_style'] = $config_info['special_product_display_style'];
		} else {
			$this->data['special_product_display_style'] = 'product-grid';
		}
		if (isset($config_info['num_of_products_special'])) {
			$this->data['num_of_products_special'] = $config_info['num_of_products_special'];
		} else {
			$this->data['num_of_products_special'] = 4;
		}
		if (isset($config_info['bestsellers_product_display_style'])) {
			$this->data['bestsellers_product_display_style'] = $config_info['bestsellers_product_display_style'];
		} else {
			$this->data['bestsellers_product_display_style'] = 'product-grid';
		}
		if (isset($config_info['num_of_products_bestsellers'])) {
			$this->data['num_of_products_bestsellers'] = $config_info['num_of_products_bestsellers'];
		} else {
			$this->data['num_of_products_bestsellers'] = 4;
		}
		if (isset($config_info['product_category_product_display_style'])) {
			$this->data['product_category_product_display_style'] = $config_info['product_category_product_display_style'];
		} else {
			$this->data['product_category_product_display_style'] = 'list-carousel';
		}
		if (isset($config_info['num_of_products_product_category'])) {
			$this->data['num_of_products_product_category'] = $config_info['num_of_products_product_category'];
		} else {
			$this->data['num_of_products_product_category'] = 3;
		}
		/*Product Item*/
		if (isset($config_info['show_name_product_item'])) {
			$this->data['show_name_product_item'] = $config_info['show_name_product_item'];
		} else {
			$this->data['show_name_product_item'] = 'yes';
		}
		if (isset($config_info['show_description_product_item'])) {
			$this->data['show_description_product_item'] = $config_info['show_description_product_item'];
		} else {
			$this->data['show_description_product_item'] = 'no';
		}
		if (isset($config_info['show_rating_product_item'])) {
			$this->data['show_rating_product_item'] = $config_info['show_rating_product_item'];
		} else {
			$this->data['show_rating_product_item'] = 'yes';
		}
		if (isset($config_info['show_wishlist_add_product_item'])) {
			$this->data['show_wishlist_add_product_item'] = $config_info['show_wishlist_add_product_item'];
		} else {
			$this->data['show_wishlist_add_product_item'] = 'yes';
		}
		if (isset($config_info['show_compare_add_product_item'])) {
			$this->data['show_compare_add_product_item'] = $config_info['show_compare_add_product_item'];
		} else {
			$this->data['show_compare_add_product_item'] = 'yes';
		}
		if (isset($config_info['product_name_color'])) {
			$this->data['product_name_color'] = $config_info['product_name_color'];
		} else {
			$this->data['product_name_color'] = '818482';
		}
		if (isset($config_info['product_name_font_family'])) {
			$this->data['product_name_font_family'] = $config_info['product_name_font_family'];
		} else {
			$this->data['product_name_font_family'] = "";
		}
		$this->data['google_font_product_name_item']=$this->model_module_treoden_cpanel->treodenGoogleFont($this->data['product_name_font_family']);
		if (isset($config_info['product_name_font_size'])) {
			$this->data['product_name_font_size'] = $config_info['product_name_font_size'];
		} else {
			$this->data['product_name_font_size'] = '14';
		}
		if (isset($config_info['price_product_color'])) {
			$this->data['price_product_color'] = $config_info['price_product_color'];
		} else {
			$this->data['price_product_color'] = '';
		}
		if (isset($config_info['product_price_font_family'])) {
			$this->data['product_price_font_family'] = $config_info['product_price_font_family'];
		} else {
			$this->data['product_price_font_family'] = "";
		}
		$this->data['google_font_product_price_item']=$this->model_module_treoden_cpanel->treodenGoogleFont($this->data['product_price_font_family']);
		if (isset($config_info['product_price_font_size'])) {
			$this->data['product_price_font_size'] = $config_info['product_price_font_size'];
		} else {
			$this->data['product_price_font_size'] = '19';
		}
		/*if (isset($config_info['old_price_product_color'])) {
			$this->data['old_price_product_color'] = $config_info['old_price_product_color'];
		} else {
			$this->data['old_price_product_color'] = '';
		}*/
		/*catalog*/
		if (isset($config_info['default_display_catalog'])) {
			$this->data['default_display_catalog'] = $config_info['default_display_catalog'];
		} else {
			$this->data['default_display_catalog'] = 'product-grid';
		}
		if (isset($config_info['columns_grid_catalog'])) {
			$this->data['columns_grid_catalog'] = $config_info['columns_grid_catalog'];
		} else {
			$this->data['columns_grid_catalog'] = 3;
		}
		if (isset($config_info['show_catalog_name'])) {
			$this->data['show_catalog_name'] = $config_info['show_catalog_name'];
		} else {
			$this->data['show_catalog_name'] = 'no';
		}
		if (isset($config_info['show_catalog_image'])) {
			$this->data['show_catalog_image'] = $config_info['show_catalog_image'];
		} else {
			$this->data['show_catalog_image'] = 'no';
		}
		if (isset($config_info['show_catalog_descriptions'])) {
			$this->data['show_catalog_descriptions'] = $config_info['show_catalog_descriptions'];
		} else {
			$this->data['show_catalog_descriptions'] = 'yes';
		}
		if (isset($config_info['show_catalog_refine_search'])) {
			$this->data['show_catalog_refine_search'] = $config_info['show_catalog_refine_search'];
		} else {
			$this->data['show_catalog_refine_search'] = 'yes';
		}
		/*Product page*/
		if (isset($config_info['enable_cloud_zoom'])) {
			$this->data['enable_cloud_zoom'] = $config_info['enable_cloud_zoom'];
		} else {
			$this->data['enable_cloud_zoom'] = 'yes';
		}
		if (isset($config_info['show_description_tab'])) {
			$this->data['show_description_tab'] = $config_info['show_description_tab'];
		} else {
			$this->data['show_description_tab'] = 'yes';
		}
		if (isset($config_info['show_reviews_tab'])) {
			$this->data['show_reviews_tab'] = $config_info['show_reviews_tab'];
		} else {
			$this->data['show_reviews_tab'] = 'yes';
		}
		if (isset($config_info['show_related_tab'])) {
			$this->data['show_related_tab'] = $config_info['show_related_tab'];
		} else {
			$this->data['show_related_tab'] = 'yes';
		}
		if (isset($config_info['num_columns_related_products'])) {
			$this->data['num_columns_related_products'] = $config_info['num_columns_related_products'];
		} else {
			$this->data['num_columns_related_products'] = 3;
		}
		$default_popup_content = array();
		foreach($this->data['languages'] as $key=>$language){
			$default_popup_content[$language['language_id']] = '<div>
			<h3>Special offers : Save up to 30%!!</h3>
			<div class="clear">&nbsp;</div>
			<div style="float:left;width:48%"><a href="#"><img alt="" src="http://treodenthemes.com/demo/timeout/watch/image/data/popup-banner.jpg" style="margin-bottom:0px" /></a></div>
			<div style="float:right;width:48%">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eget erat ipsum. Sed ultrices ante tortor, eu viverra metus facilisis vitae. Donec mollis sit amet velit ut bibendum.</div>
			<div class="clear">&nbsp;</div>
			</div>';
		}
		if (isset($config_info['popup_content'])) {
			$this->data['popup_content'] = unserialize(base64_decode($config_info['popup_content']));
		} else {
			$this->data['popup_content'] = $default_popup_content;
		}
		if (isset($config_info['time_open_again_popup'])) {
			$this->data['time_open_again_popup'] = $config_info['time_open_again_popup'];
		} else {
			$this->data['time_open_again_popup'] = '24';
		}
		if (isset($config_info['width_popup'])) {
			$this->data['width_popup'] = $config_info['width_popup'];
		} else {
			$this->data['width_popup'] = '450';
		}
		if (isset($config_info['height_popup'])) {
			$this->data['height_popup'] = $config_info['height_popup'];
		} else {
			$this->data['height_popup'] = '350';
		}
		if (isset($config_info['display_popup'])) {
			$this->data['display_popup'] = $config_info['display_popup'];
		} else {
			$this->data['display_popup'] = 'yes';
		}
		
		$this->template = 'module/treoden_config_form.tpl';
		$this->children = array(
			'common/header',
			'common/footer'
		);
				
		$this->response->setOutput($this->render());
	}

	protected function validateForm() {
		if (!$this->user->hasPermission('modify', 'module/treoden_cpanel')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}				
		if ($this->error && !isset($this->error['warning'])) {
			$this->error['warning'] = $this->language->get('error_warning');
		}
					
		if (!$this->error) {
			return true;
		} else {
			return false;
		}
	}	
	
	public function ajaxLayout(){
		$store_id = $this->request->post['store_id'];
		$layout_id=$this->request->post['layout_id'];
		$layout_name=$this->request->post['layout_name'];
		$this->load->model('module/treoden_cpanel');
		$layout_info = $this->model_module_treoden_cpanel->treodenGetLayout($store_id, $layout_id);
		if($this->model_module_treoden_cpanel->treodenGetOption($store_id, "sort_order_top_".$layout_id))	
		{
			$sort_order_top = $this->model_module_treoden_cpanel->treodenGetOption($store_id, "sort_order_top_".$layout_id);
			$sort_order_top = $sort_order_top['value'] ? $sort_order_top['value'] : 0;
		}
		else
			$sort_order_top = 0;
		if($this->model_module_treoden_cpanel->treodenGetOption($store_id, "sort_order_bottom_".$layout_id))	
			{
				$sort_order_bottom = $this->model_module_treoden_cpanel->treodenGetOption($store_id, "sort_order_bottom_".$layout_id);
				$sort_order_bottom = $sort_order_bottom['value'] ? $sort_order_bottom['value'] : 0;
			}
		else
			$sort_order_bottom = 0;
		$left_style ="";	
		$right_style ="display:none";	
		$content_style ="";	
		$content_class ="span9";	
		if($layout_info['layout_column']=='two-columns-right' or $layout_info['layout_column']=='one-column')
			$left_style ="display:none";	
		if($layout_info['layout_column']=='two-columns-right' or $layout_info['layout_column']=='three-columns')
			$right_style ="display:block";	
		if($layout_info['layout_column']=='three-columns')	
			$content_class ="span6";	
		if($layout_info['layout_column']=='one-column')	{
			$content_class ="span12";
			$content_style ="margin-left:0px!important";				
		}
		if($left_style=="display:none")	
			$content_class = $content_class." first";
		?>
		<div id="layout_editor">
			<input type="hidden" name="layout_id" value="<?php echo $layout_id;?>" />
			<input id="sort-order-top" type="hidden" name="sort_order_top" value="<?php echo $sort_order_top;?>" />
			<input id="sort-order-bottom" type="hidden" name="sort_order_bottom" value="<?php echo $sort_order_bottom;?>" />
			<div id="editor-area">
				
				<div class="container">
					<div>
						<div class="select_column">
							<div><h4>You are editing <?php echo $layout_name;?> layout</h4></div>
							<p>Change Layout :</p> 
							<select id="select-column" name="columns" onchange="change_mzlayout(this);">
								<option value="one-column" <?php if($layout_info['layout_column'] =='one-column') echo "selected='selected'";?>>One Column</option>
								<option value="two-columns-left" <?php if($layout_info['layout_column'] =='two-columns-left' or !$layout_info) echo "selected='selected'";?>>Two Columns Left</option>
								<option value="two-columns-right" <?php if($layout_info['layout_column'] =='two-columns-right') echo "selected='selected'";?>>Two Columns Right</option>
								<option value="three-columns" <?php if($layout_info['layout_column'] =='three-columns') echo "selected='selected'";?>>Three Columns</option>
							</select>
						</div>
					</div>
					<div class="row-fluid">
						<div class="span3 left-sidebar" style="<?php echo $left_style;?>">
							<div class="inner" style="border:4px dashed #ddd;min-height:650px">	
								<div style="font-size:22px;color:#ccc;text-align:center">Position : Column Left</div>
							</div>
						</div>
						<div id="main-content" class="<?php echo $content_class;?>" style="<?php echo $content_style;?>">
								<div class="regions top-content" style="min-height:300px;margin-bottom:40px">
									<ul style="margin:0px;cursor:move" class="sortable"><?php $this->model_module_treoden_cpanel->treodenLoadGridTop($store_id, $layout_id);?></ul>
									<div style="text-align:center;margin-top:15px"><a href="javascript:void(0);" class="add-block btn top">Add Block</a></div>
									<div style="font-size:22px;color:#ccc;text-align:center">Position : Content Top</div>
								</div>	 
								<div class="regions bottom-content" style="min-height:300px;">
									<div style="text-align:center;margin-top:15px"><a href="javascript:void(0);"  class="add-block btn bottom">Add Block</a></div>
									<div style="font-size:22px;color:#ccc;text-align:center">Position : Content Bottom</div>
									<ul style="margin:0px;cursor:move" class="sortable"><?php $this->model_module_treoden_cpanel->treodenLoadGridBottom($store_id, $layout_id);?></ul>
								</div>	
						</div>
						<div class="span3 right-sidebar" style="<?php echo $right_style;?>">
							<div class="inner" style="border:4px dashed #ddd;min-height:650px">	
								<div style="font-size:22px;color:#ccc;text-align:center">Position : Column Right</div>
							</div>
						</div>		
					</div>
				</div>
			</div>
		</div>
		<script>
			var sort_order_top = parseInt(<?php echo $sort_order_top;?>);
			var sort_order_bottom = parseInt(<?php echo $sort_order_bottom;?>);
			var html_block = "<li class='row-fluid new' style='margin-bottom:15px;border:4px dashed #ddd;min-height:75px'>"+
			"<div style='margin: 10px 0px 0px 10px'>"+
				"<a onclick='setting_grid(this);' style='margin-right:10px' class='decrease icon-wrench' href='javascript:void(0);'></a>"+
				"<a onclick='remove_block(this);' class='remove icon-remove' href='javascript:void(0);'></a>"+
			'</div>'+
			'<div class="sort-order-note" style="text-align:center;font-size:18px;color:#ccc"></div>'+
			'<div class="list-options" style="display:none;width:98%;margin:10px auto">'+
				'<div style="margin:10px 0px">Click To Select Layout For Block</div>'+
				'<div onclick="reset_block(this);" class="row-fluid" style="margin-bottom:15px">'+
					'<div class="span12" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
				'</div>'+
				'<div onclick="select_layout_block(this);" class="row-fluid" style="margin-bottom:15px">'+
					'<div class="span3" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span3" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span3" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span3" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
				'</div>'+
				'<div onclick="select_layout_block(this);" class="row-fluid" style="margin-bottom:15px">'+
					'<div class="span6" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span3" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span3" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
				'</div>'+
				'<div onclick="select_layout_block(this);" class="row-fluid" style="margin-bottom:15px">'+
					'<div class="span3" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span3" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span6" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
				'</div>'+
				'<div onclick="select_layout_block(this);" class="row-fluid" style="margin-bottom:15px">'+
					'<div class="span3" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span6" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span3" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
				'</div>'+
				'<div onclick="select_layout_block(this);" class="row-fluid" style="margin-bottom:15px">'+
					'<div class="span4" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span4" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span4" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
				'</div>'+
				'<div onclick="select_layout_block(this);" class="row-fluid" style="margin-bottom:15px">'+
					'<div class="span3" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span9" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
				'</div>'+
				'<div onclick="select_layout_block(this);" class="row-fluid" style="margin-bottom:15px">'+
					'<div class="span4" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span8" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
				'</div>'+
				'<div onclick="select_layout_block(this);" class="row-fluid" style="margin-bottom:15px">'+
					'<div class="span9" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span3" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
				'</div>'+
				'<div onclick="select_layout_block(this);" class="row-fluid" style="margin-bottom:15px">'+
					'<div class="span8" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span4" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
				'</div>'+
				'<div onclick="select_layout_block(this);" class="row-fluid" style="margin-bottom:15px">'+
					'<div class="span6" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
					'<div class="span6" style="height:50px;"><div style="border:1px solid #ddd;height:100%"></div></div>'+
				'</div>'+
			'</div>'+
			'<div class="row-fluid selected" style="width:98%;margin:10px auto"></div>'
			'</li>';
			
			function reset_block(opt){
				$(opt).parent().parent().children('.selected').html('');
				$(opt).parent().parent().children('.sort-order-note').show();
				$(opt).parent().hide();
			}
			function phare_sort_order(opt, start){
				var num_block = $(opt).parent().parent().children('.selected').children('div').length;
				var sort_step = 12/num_block - 1;
				if(num_block >= 1){
					$(opt).parent().parent().children('.selected').children('div').each(function(index, e){
						var term_start = start;
						var term_end = start + sort_step;
						start = term_end + 1 ;
						var html = "<div style='text-align:center;font-size:15px;color:#fff;height:100%;line-height:50px'>Sort Order From " + term_start + " To " + term_end + "</div>";
						$(e).attr('sort_order_start', term_start);
						$(e).attr('sort_order_end', term_end);
						$(e).children('div').html(html);
					})
				}
				else{
					$(opt).attr('sort_order_start', start);
					$(opt).attr('sort_order_end', start + 11);
				}
			}
			function change_mzlayout(obt){
				var layout = $(obt).val();
				if(layout=="one-column"){
					$('.left-sidebar').hide();
					$('.right-sidebar').hide();
					$('#main-content').removeClass().addClass('span12').css('margin-left', '0px');
				}
				if(layout=="two-columns-left"){
					$('.left-sidebar').show();
					$('.right-sidebar').hide();
					$('#main-content').removeClass().addClass('span9').css('margin-left', '2.5641%');
				}
				if(layout=="two-columns-right"){
					$('.left-sidebar').hide();
					$('.right-sidebar').show();
					$('#main-content').removeClass().addClass('span9').css('margin-left', '0px');
				}
				if(layout=="three-columns"){
					$('.left-sidebar').show();
					$('.right-sidebar').show();
					$('#main-content').removeClass().addClass('span6').css('margin-left', '2.5641%');
				}
			}
			function setting_grid(opt){
				if($(opt).parent().parent().children('.list-options').is(':visible')){
					//$(opt).removeClass('active');
					$(opt).parent().parent().children('.list-options').hide();
				}else{
					//$(opt).addClass('active');
					$(opt).parent().parent().children('.list-options').show();
				}
			}
			function select_layout_block(opt){
				var html = $(opt).html();
				$(opt).parent().parent().children('.selected').html('');
				$(opt).parent().parent().children('.selected').html(html);
				$(opt).parent().parent().children('.sort-order-note').hide();
				$(opt).parent().hide();
				var sort_order_start = parseFloat($(opt).parent().parent().attr('sort_order_start'));
				phare_sort_order(opt, sort_order_start);
				
			}
			function remove_block(opt){
				$(opt).parent().parent().remove();
			}
			$('.regions').each(function(){
				if($(this).children('.sortable').children('li').length == 0)
					$(this).css('border', '4px dashed #ddd');
			})
			$('a.add-block').click(function(){
				if($(this).hasClass('top')==true)
					var sort_order_start = parseInt(sort_order_top);
				if($(this).hasClass('bottom')==true)
					var sort_order_start = parseInt(sort_order_bottom);	
				var sort_order_end = parseInt(sort_order_start + 11);
				$(this).parent().parent().css('border', 'none')
				$(this).parent().parent().children('.sortable').append(html_block);
				var note = "Sort Order From " + sort_order_start + " To " + sort_order_end;
				$(this).parent().parent().children('.sortable').children("li:last").children('.sort-order-note').text(note);
				$(this).parent().parent().children('.sortable').children("li:last").attr('sort_order_start', sort_order_start);
				$(this).parent().parent().children('.sortable').children("li:last").attr('sort_order_end', sort_order_end);
				if($(this).hasClass('top')==true){
					sort_order_top = parseInt(sort_order_end + 1);
					$('input#sort-order-top').attr( 'value', sort_order_top );
				}
				if($(this).hasClass('bottom')==true){
					sort_order_bottom = parseInt(sort_order_end + 1);
					$('input#sort-order-bottom').attr('value', sort_order_bottom);
				}
			});
			$('#select-column').change(function(){
				var content_
				var layout = $(this).val();
				if(layout=='one-column'){
					
				}
				if(layout=='one-column'){
					
				}
				if(layout=='one-column'){
					
				}
				if(layout=='one-column'){
					
				}
			});
			$( ".sortable" ).sortable();
		</script>
		<style>
			.list-options > .row-fluid:hover > div{background:gray}
			.selected > div > div{background:#ccc;border:none!important}
		</style>
		<?php
		die;
	}
	public function ajaxExport(){
		if(!$this->validateForm())
			echo "You have no permission to edit treoden Cpanel";
		else{
			$this->load->model('module/treoden_cpanel');
			$config_info = $this->model_module_treoden_cpanel->getSetting( $this->request->get['store_id']);
			$output = "<?xml version=\"1.0\" ?>\n";
			$output .= "<schema>\n"; 
			$output .= "<filecheck>"; 
			$output .= md5('treoden');
			$output .= "</filecheck>\n"; 
			$output .= "<option>\n"; 
			foreach($config_info as $key=>$value){
				if(!$value)
					$value='';
				// $value = str_replace(array("\x00", "\x0a", "\x0d", "\x1a"), array('\0', '\n', '\r', '\Z'), $value);
				// $value = str_replace(array("\n", "\r", "\t"), array('\n', '\r', '\t'), $value);
				// $value = str_replace('\\', '\\\\',	$value);
				// $value = str_replace('\'', '\\\'',	$value);
				// $value = str_replace('\\\n', '\n',	$value);
				// $value = str_replace('\\\r', '\r',	$value);
				// $value = str_replace('\\\t', '\t',	$value);	
				$output .="<row>\n";
				$output .="<name>".$key."</name>\n";
				$output .="<value>".$value."</value>\n";
				$output .="</row>\n";
			}
			$output .= "</option>\n"; 
			$layout_info = $this->model_module_treoden_cpanel->treodenGetLayouts($this->request->get['store_id']);
			if($layout_info) : 
			//var_dump($layout_info);
			$output .= "<layout>\n"; 
			foreach($layout_info as $key=>$value){
				// $value = str_replace(array("\x00", "\x0a", "\x0d", "\x1a"), array('\0', '\n', '\r', '\Z'), $value);
				// $value = str_replace(array("\n", "\r", "\t"), array('\n', '\r', '\t'), $value);
				// $value = str_replace('\\', '\\\\',	$value);
				// $value = str_replace('\'', '\\\'',	$value);
				// $value = str_replace('\\\n', '\n',	$value);
				// $value = str_replace('\\\r', '\r',	$value);
				// $value = str_replace('\\\t', '\t',	$value);	
				$output .="<row>\n";
				$output .="<id>".$value['layout_id']."</id>\n";
				$output .="<name>".$value['layout_name']."</name>\n";
				$output .="<column>".$value['layout_column']."</column>\n";
				$output .="<top>".$value['content_top']."</top>\n";
				$output .="<bottom>".$value['content_bottom']."</bottom>\n";
				$output .="</row>\n";
			}
			endif;
			$output .= "</layout>\n"; 
			$output .= "</schema>\n";
			$file_name = 'treoden-cpanel-configuration-'.time().'.xml';
			$file = DIR_CACHE . $file_name;
			$handle = fopen($file, 'w');
			fwrite($handle, $output);
			fclose($handle);
			if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1')))
				$file_url = HTTPS_CATALOG . "system/cache/".$file_name;
			else
				$file_url = HTTP_CATALOG . "system/cache/".$file_name;
			echo $file_url; 
		}
	}
	public function import(){
		$this->language->load('module/treoden_cpanel');
		$this->document->setTitle($this->language->get('meta_title'));
		if(($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
			$this->load->model('module/treoden_cpanel');
			$file = $this->request->files['file'];
			$store_id=$this->request->get['store_id'];
			$file_name = $file['name'];
			$uploadPath = $file['tmp_name'];
			if($file['type']!="text/xml"){
				$this->error['warning'] = "Invalid file";
			}else{
				$xml=simplexml_load_file($uploadPath);
				$md5 = $xml->filecheck->__toString();
				if(md5('treoden')!=trim($md5))
				{
					$this->error['warning'] = "Invalid file";
				}
				else{
					$option = $xml->option;
					$layout = $xml->layout;
					$option_data = array();
					foreach($option->row as $val){
						$option_data[trim($val->name->__toString())] = trim($val->value->__toString());
					}
					$this->model_module_treoden_cpanel->treodenSaveSettingOption($store_id, $option_data);
					$layout_data = array();
					foreach($layout->row as $val){
						$layout_data['layout_id'] = trim($val->id->__toString());
						$layout_data['layout_name'] = trim($val->name->__toString());
						$layout_data['layout_column'] = trim($val->column->__toString());
						$layout_data['content_top'] = trim($val->top->__toString());
						$layout_data['content_bottom'] = trim($val->bottom->__toString());
						$this->model_module_treoden_cpanel->treodenUpdateLayout($store_id, $layout_data['layout_id'], $layout_data);
					}
					$this->session->data['success'] = $this->language->get('text_success');					
				}
			}
		}
		$this->getList();
	}
}
?>